package com.wlhse.controller;

import com.wlhse.entity.ProblemSourcePojo;
import com.wlhse.service.ProblemSourceService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("ProblemSourceController")
@RequestMapping("/api/v3")
//问题原因
public class ProblemSourceController {

    @Resource
    private ProblemSourceService problemSourceService;

    @RequestMapping(value = "/problem_sources", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String insertProblemSource(@RequestBody(required = false) ProblemSourcePojo planSourcePojo) {
            return problemSourceService.insertProblemSource(planSourcePojo);
    }

    @RequestMapping(value = "/problem_sources/{id}", method = RequestMethod.DELETE, produces = "application/json; charset=utf-8")
    public String removeProblemSource(@PathVariable int id) {
        return problemSourceService.removeProblemSource(id);
    }

    @RequestMapping(value = "/problem_sources/{id}", method = RequestMethod.PUT, produces = "application/json; charset=utf-8")
    public String updateProblemSource(@PathVariable("id") int id, @RequestBody(required = false) ProblemSourcePojo planSourcePojo) {
        planSourcePojo.setProblemSourceID(id);
        return problemSourceService.updateProblemSource(planSourcePojo);
    }

    //分页查
    @RequestMapping(value = "/problem_sources", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String listProblemSource(@ModelAttribute ProblemSourcePojo pojo) {
        return problemSourceService.listProblemSource(pojo);
    }

    //查 By Id
    @RequestMapping(value = "/problem_sources/{id}", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String queryProblemSourceyId(@PathVariable int id) {
        return problemSourceService.queryProblemSourceyId(id);
    }

    //模糊查
    @RequestMapping(value = "/problem_sources/keyword/{keyword}", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String queryProblemSourceByVagueCondition(@PathVariable String keyword) {
        return problemSourceService.queryProblemSourceByVagueCondition(keyword);
    }

    @RequestMapping(value = "/problem_sources/sourceName", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String queryProblemSourceBySourceName(@ModelAttribute ProblemSourcePojo problemSourcePojo) {
        return problemSourceService.queryProblemSourceBySourceName(problemSourcePojo);
    }
}